import javax.swing.plaf.synth.SynthOptionPaneUI;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

public class Home {

    public static void main(String[] args) throws Exception {


        ToolsOfMoney toolsOfMoney = new ToolsOfMoney();
        Scanner scanner = new Scanner(System.in);
        toolsOfMoney.logon();
        int nowdeposit;

        while (true) {
            // 循环体中的代码会无限重复执行
            System.out.println("-------------零钱通菜单-------------");
            System.out.println("\t\t\t1.零钱通明细");
            System.out.println("\t\t\t2.收益 入账");
            System.out.println("\t\t\t3.消 费");
            System.out.println("\t\t\t4.退 出");
            System.out.println("请选择(1-4)");
            String name;
//            List<poketmoney> selectDataall = ToolsOfMoney.selectlistReflect("select * from poketmoney   ", poketmoney.class);
//            for (poketmoney fruit : selectDataall) {
//                System.out.print(" \t\t\t\t" + fruit.getPoject());
//                System.out.print("\t\t\t\t " + fruit.getPay());
//                System.out.print("\t\t\t\t " + fruit.getTime());
//                System.out.print("\t\t\t\t " + fruit.getDeposit());
//
//
//                System.out.println("");
//            }

//            System.out.println("selectDataall = " + selectDataall);


            int a = scanner.nextInt();
            switch (a) {

                case 1:
                    List<poketmoney> selectDataall = ToolsOfMoney.selectlistReflect("select * from poketmoney   ", poketmoney.class);
                    for (poketmoney fruit : selectDataall) {
                        System.out.print(" \t\t\t" + fruit.getPoject());
                        System.out.print("\t\t\t" + fruit.getPay());
                        System.out.print("\t\t\t " + fruit.getTime());
                        System.out.print("\t\t\t " + fruit.getDeposit());


                        System.out.println("");
                    }
                    break;

                // 可选
                case 2:


                    System.out.println("请输入入账钱数：");
                    scanner = new Scanner(System.in);
                    String next = scanner.next();

                    poketmoney selyi = ToolsOfMoney.selectData("select deposit from poketmoney order by time desc", poketmoney.class);
                    Integer b = selyi.getDeposit() + Integer.valueOf(next);
                    Date date = new Date();
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    ToolsOfMoney.insert("INSERT INTO poketmoney  VALUES (?,?,?,?,?)", null, "收入", next, sdf.format(date), b);
                    System.out.println("收入后的余额为" + b);

                    List<poketmoney> selectDataall2 = ToolsOfMoney.selectlistReflect("select * from poketmoney   ", poketmoney.class);
                    for (poketmoney fruit : selectDataall2) {
                        System.out.print(" \t\t\t\t" + fruit.getPoject());
                        System.out.print("\t\t\t\t " + fruit.getPay());
                        System.out.print("\t\t\t\t " + fruit.getTime());
                        System.out.print("\t\t\t\t " + fruit.getDeposit());


                        System.out.println("");
                    }
                    break;


//                System.out.println("请输入输入你上次的支出");
//                int expenditure = scanner.nextInt();
//                System.out.println("请输入输入你上次的收入");
//                int revenue = scanner.nextInt();
//                money_javabean selectdeposit = ToolsOfMoney.selectData("select * from money where name=? ", money_javabean.class, "邓思晗");
//                System.out.println("selectdeposit = " + selectdeposit);
//                int originaldeposit = selectdeposit.getDeposit();
//                System.out.println("你原来的余额为 = " + originaldeposit);
//                nowdeposit=  originaldeposit-expenditure+revenue;
//                System.out.println("你现在的余额为 " + nowdeposit);
//
//                int updateData = ToolsOfMoney.updateData("update money set deposit=? where name=? ", nowdeposit, "邓思晗");
//                if(updateData==1){
//                    System.out.println("你现在的余额为 " + nowdeposit);
//
//                }
                // 可选
                // 可以有更多的case子句
                case 3:


                    System.out.printf("消费金额");
                    int i = scanner.nextInt();
                    System.out.printf("消费说明");
                    next = scanner.next();
                    selyi = ToolsOfMoney.selectData("select deposit from poketmoney order by time desc", poketmoney.class);
                    b = selyi.getDeposit() - i;
                    date = new Date();
                    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                    int insert = ToolsOfMoney.insert("INSERT INTO poketmoney  VALUES (?,?,?,?,?)", null, next, i, sdf.format(date), b);
                    System.out.println("insert = " + insert);
                    List<poketmoney> selectDataall3 = ToolsOfMoney.selectlistReflect("select * from poketmoney   ", poketmoney.class);
                    for (poketmoney fruit : selectDataall3) {
                        System.out.print(" \t\t\t\t" + fruit.getPoject());
                        System.out.print("\t\t\t\t " + fruit.getPay());
                        System.out.print("\t\t\t\t " + fruit.getTime());
                        System.out.print("\t\t\t\t " + fruit.getDeposit());


                        System.out.println("");
                    }
                    break;

//                List<poketmoney> selectDataall1 = ToolsOfMoney.selectlistReflect("select * from poketmoney   ", poketmoney.class);
//
//                System.out.println("selectDataall = " + selectDataall1);


                case 4:
                    System.out.printf("您已选择退出");
                    break;


                case 5:


                    break;


            }
            if (a == 4) {
                break;
            }

            // 注意：这里缺少任何跳出循环的条件（如break语句）
        }


        /**
         * c查询
         */
//        money_javabean selectData = ToolsOfMoney.selectData("select * from money where name=? ", money_javabean.class, name);
//        System.out.printf("您的的余额是");
//        System.out.println(selectData.getDeposit());

        /**
         * 更改
         */

//        System.out.println("请输入输入你上次的支出");
//        int expenditure = scanner.nextInt();
//        System.out.println("请输入输入你上次的收入");
//        int revenue = scanner.nextInt();
//        money_javabean selectdeposit = ToolsOfMoney.selectData("select * from money where name=? ", money_javabean.class, name);
//        System.out.println("selectdeposit = " + selectdeposit);
//        int originaldeposit = selectdeposit.getDeposit();
//        System.out.println("originaldeposit = " + originaldeposit);
//        nowdeposit=  originaldeposit-expenditure+revenue;
//
//        int updateData = ToolsOfMoney.updateData("update money set deposit=? where name=? ", nowdeposit, name);
//        System.out.printf("你现在的余额为");


    }

}
